import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { projectsData, projectCategories } from '@/data/projects'

export const useProjectsStore = defineStore('projects', () => {
  // 项目列表
  const projects = ref(projectsData)
  
  // 当前选中的分类
  const currentCategory = ref('all')
  
  // 分类列表
  const categories = ref(projectCategories)
  
  // 过滤后的项目列表
  const filteredProjects = computed(() => {
    if (currentCategory.value === 'all') {
      return projects.value
    }
    return projects.value.filter(p => p.category === currentCategory.value)
  })
  
  // 精选项目
  const featuredProjects = computed(() => {
    return projects.value.filter(p => p.featured)
  })
  
  // 根据 ID 获取项目
  function getProjectById(id) {
    return projects.value.find(p => p.id === Number(id))
  }
  
  // 设置分类
  function setCategory(category) {
    currentCategory.value = category
  }
  
  return {
    projects,
    currentCategory,
    categories,
    filteredProjects,
    featuredProjects,
    getProjectById,
    setCategory
  }
})

